package com.example.back.mapper;

import cn.hutool.core.date.DateTime;
import com.example.back.dto.resp.DepartOrderRsp;
import com.example.back.dto.resp.DoctorOrderRsp;
import com.example.back.dto.resp.GetServiceDataCountResp;
import com.example.back.dto.resp.OrderMainRspT;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@Component
public interface MainMapper {
    @Select("SELECT COUNT(1) AS countDay FROM order_main WHERE system_status_tinyint=2 AND oc_status_tinyint IN(0,1,2)" +
            " AND create_time_datetime>#{dateTime}")
    Integer countDay(@Param("dateTime") DateTime dateTime);

    @Select("SELECT COUNT(1) AS countPatint FROM client_patients_info WHERE disable_bit=TRUE")
    Integer countPatint();

    @Select("SELECT COUNT(1) AS countPatint FROM doctor_base_info WHERE disable=TRUE AND is_online =TRUE")
    Integer countDocter();

    @Select("SELECT COUNT(1) AS countPatint FROM doctor_pharmacist WHERE disable_bit=TRUE AND is_online_bit =TRUE")
    Integer countPharmacist();

    @Select("SELECT a.name_nvarchar AS Name,c.service_int AS Service,c.prescription_int AS Prescription,c.praise_decimal " +
            "AS Praise FROM h_hospital_department a INNER JOIN doctor_base_info b ON(a.id_bigint=b.depart_id) " +
            "INNER JOIN doctor_ex_info c ON (b.dc_id=c.dc_id_bigint)")
    List<DepartOrderRsp> DepartOrder();

    @Select("SELECT b.name AS Name, a.name_nvarchar  AS depName,  b.title AS Title ,c.service_int AS Service,c.prescription_int AS" +
            " Prescription,c.praise_decimal AS Praise FROM h_hospital_department a INNER JOIN doctor_base_info b " +
            "ON(a.id_bigint=b.depart_id) INNER JOIN doctor_ex_info c ON (b.dc_id=c.dc_id_bigint) ORDER BY c.service_int DESC ,c.praise_decimal DESC LIMIT 5")
    List<DoctorOrderRsp> docterOrderBy();

    @Select("SELECT ask_money_money FROM order_main WHERE system_status_tinyint=2 AND oc_status_tinyint IN(0,1,2) AND create_time_datetime>=#{endOfDay}")
    List<Double> TodayService(@Param("endOfDay") DateTime begnOfDay);

    @Select("SELECT sale_price_money FROM order_rx_main WHERE system_status_tinyint =2 AND order_back_tinyint =FALSE AND create_time_datetime>=#{beginOfDay}")
    List<Double> TodayDrug(@Param("beginOfDay") DateTime beginOfDay);

    @Select("SELECT ask_money_money AS askMoney,create_time_datetime  AS date ,order_no_nvarchar AS orderNo FROM order_main  WHERE system_status_tinyint=2 AND oc_status_tinyint IN(0,1,2) " +
            "AND create_time_datetime BETWEEN #{beg} AND #{end}")
    List<OrderMainRspT> orderMainList(@Param("beg") Date beg, @Param("end") Date end);

    @Select("SELECT sale_price_money FROM order_rx_main WHERE order_no_nvarchar =#{orderNo}")
    List<Double> queryByOrderNo(@Param("orderNo") String orderNo);

    List<GetServiceDataCountResp> GetServiceData(@Param("sbeg") Date sbeg, @Param("send") Date send);
}
